﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Isha.Entities;
using Isha.Services.Infrastructure;
using Isha.Repositories.Infrastructure;
using Isha.Data.Infrastructure;
using System.Web.Mvc;
using Isha.Repositories;

namespace Isha.Services
{
    internal class LanguageService : ServiceBase, ILanguageService
    {
        public LanguageService()
        {
            Initialize(null, null);
        }

        public LanguageService(ILanguageRepository languageRepository, IUnitOfWork unitOfWork)
        {
            Initialize(languageRepository, unitOfWork);
        }

        public ILanguageRepository LanguageRepository { get; private set; }

        public IUnitOfWork UnitOfWork { get; private set; }

        public void Initialize(ILanguageRepository languageRepository, IUnitOfWork unitOfWork)
        {            
            LanguageRepository = (languageRepository ?? DependencyResolver.Current.GetService<ILanguageRepository>());
            UnitOfWork = (unitOfWork ?? DependencyResolver.Current.GetService<IUnitOfWork>());
        }

        public IEnumerable<Language> GetLanguages()
        {
            var languages = LanguageRepository.GetAll();
            return languages;
        }

        public Language GetLanguage(long id)
        {
            var language = LanguageRepository.Find(id);
            return language;
        }

        public void CreateLanguage(Language language)
        {
            LanguageRepository.Add(language);
            UnitOfWork.Commit();
        }

        public void DeleteLanguage(long id)
        {
            LanguageRepository.Delete(id);
            UnitOfWork.Commit();
        }


    }
}
